<?php
/**
 * Controller for app
 */
require_once 'app/env.php';
//show submit form, or do feedback saving
if (isset($_GET['action'])) {
	switch($_GET['action']) {
	    /**
	     * Action saves feedback form
	     */
		case 'save' :
			$view = new Views\Feedback();
			$view->saveForm($_POST);
		break;
		/**
		 * Action logs user in
		 */
		case 'login':
			$view = new Views\Account();
			$view->login($_POST);
			break;
		/**
		 * Action logs user out
		 */
		case 'logout':
			$view = new Views\Account();
			$view->logout();
			break;
		/**
		 * Action updates company details
		 */
		case 'updateCompany':
			//store company details
			$view = new \Views\Business();
			$view->updateCompany($_POST);
			break;
		/**
		 * Action registers user
		 */
		case 'registerAccount':
			$view = new Views\Account();
			$view->register($_POST);
			break;
		/**
		 * Action updates user info
		 */
		case 'updateAccount':
			$view = new Views\Account();
			$view->updateAccount($_POST);
			break;
	}
	
} else {
	switch (@$_GET['page']) {
	    /**
	     * Page shows feedback form
	     */
		case 'feedback':
			$view = new Views\Feedback();
			$view->viewForm($_GET['b']);
		    break;
	    /**
	     * Page shows feedback form for handheld devices
	     */
		case 'fb':
		    $view = new Views\Feedback();
		    $view->viewPortableForm($_GET['b']);
		    break;
	    /**
	     * Page shows top companies list
	     */
		case 'bestCompanies':
			$view = new Views\Business();
			$catId = (int)@$_GET['b'];
			if ($catId == 0) {
				$catId = 1;
			}
			$view->viewTopBusinesses($catId);
			break;
		/**
		 * Page shows businesses scores and comments page
		 */
		case 'myComments':
			$view = new Views\Business();
			$view->viewMyScoresAndComments((int)@$_GET['b']);
			break;
		/**
		 * Page shows businesses NPS graphics
		 */
		case 'myAnalytics':
			$view = new Views\Business();
			$view->viewMyAnalytics((int)@$_GET['b']);
			break;
		/**
		 * Page shows registration form
		 */
		case 'signup':
			$view = new \Views\Account();
			$view->viewRegistraitionForm();
			break;
		/**
		 * Page shows business details view
		 */
		case 'companyDetails':
			$view = new Views\Business();
			$view->viewBusinessDetails((int)@$_GET['b']);
			break;
        /**
         * Page shows sign in form
         */
		case 'signin':
			$view = new Views\Account();
			$view->displayStatic('signin.tpl');
			break;
		/**
		 * Page shows edit company form
		 */
		case 'editCompany':
			$view = new Views\Business();
			$view->viewEditCompanyForm((int)@$_GET['b']);
			break;
		/**
		 * Page shows contacts view
		 */
		case 'contact':
			$view = new Views\Page();
			$view->displayStatic('contacts.tpl');
			break;
		/**
		 * Page shows edit user form
		 */
		case 'editUser':
			$view = new Views\Account();
			$view->viewEditAccountFrom((int)$_GET['b']);
			break;
		/**
		 * Default page is welcome page (landing)
		 */
		default:
			$view = new Views\Page();
			$view->displayStatic('welcome.tpl');
		break;
	}
	
}
